package com.jindy.module.salary.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jindy.common.core.domain.entity.SysUser;
import com.jindy.common.utils.SecurityUtils;
import com.jindy.module.salary.domain.Salary;
import com.jindy.module.salary.service.ISalaryService;
import com.jindy.system.service.ISysUserService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jindy.common.annotation.Log;
import com.jindy.common.core.controller.BaseController;
import com.jindy.common.core.domain.AjaxResult;
import com.jindy.common.enums.BusinessType;
import com.jindy.common.utils.poi.ExcelUtil;
import com.jindy.common.core.page.TableDataInfo;

/**
 * 薪资Controller
 *
 * @author ruoyi
 * @date 2022-09-28
 */
@RestController
@RequestMapping("/module/salary")
public class SalaryController extends BaseController
{
    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private ISysUserService sysUserService;

    /**
     * 查询薪资列表
     */
    @PreAuthorize("@ss.hasPermi('module:salary:list')")
    @GetMapping("/list")
    public TableDataInfo list(Salary salary)
    {
        //添加权限
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        salary.setUserId(sysUser.getUserId());
        startPage();
        List<Salary> list = salaryService.selectSalaryList(salary);
        return getDataTable(list);
    }

    /**
     * 导出薪资列表
     */
    @Log(title = "薪资", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('module:salary:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, Salary salary)
    {
        //添加权限
        SysUser sysUser = SecurityUtils.getLoginUser().getUser();
        salary.setUserId(sysUser.getUserId());

        List<Salary> list = salaryService.selectSalaryList(salary);
        ExcelUtil<Salary> util = new ExcelUtil<Salary>(Salary.class);
        util.exportExcel(response, list, "薪资数据");
    }

    /**
     * 获取薪资详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:salary:id')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(salaryService.selectSalaryById(id));
    }

    /**
     * 新增薪资
     */
    @Log(title = "薪资", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('module:salary:add')")
    @PostMapping
    public AjaxResult add(@RequestBody Salary salary)
    {
        return toAjax(salaryService.insertSalary(salary));
    }

    /**
     * 修改薪资
     */
    @Log(title = "薪资", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('module:salary:update')")
    @PutMapping
    public AjaxResult edit(@RequestBody Salary salary)
    {
        return toAjax(salaryService.updateSalary(salary));
    }

    /**
     * 删除薪资
     */
    @Log(title = "薪资", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('module:salary:delete')")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(salaryService.deleteSalaryByIds(ids));
    }
}
